import json
def generate_json(system_content, user_content, assistant_content):
   messages = [
       {"role": "system", "content": system_content},
       {"role": "user", "content": user_content},
       {"role": "assistant", "content": assistant_content}
   ]

   data = {"messages": messages}

   # 将字典转换为JSON字符串
   json_string = json.dumps(data, ensure_ascii=False, indent=4)
   json_string = json_string.replace('\n', '')
   return json_string


def read_and_output_file(file_path):
    
  try:
      with open(file_path, 'r', encoding='utf-8') as file:
          for line_number, line in enumerate(file, start=1):
              if "发送数据给NCC" in line:
                   str1 = generate_json("你是CNE的数据核查人员，根据关键词返回结果",line,"YES")
                   print(str1)


              else:
                   str1 = generate_json("你是CNE的数据核查人员，根据关键词返回结果",line,"NO")
                   print(str1)

  except FileNotFoundError:
      print(f"Error: The file '{file_path}' does not exist.")
  except Exception as e:
      print(f"An error occurred: {e}")
 
def main():
  read_and_output_file('basedata')
 
if __name__ == "__main__":
  main()
